//
//  ZhouModel.m
//  好粥到
//
//  Created by quan on 15/11/16.
//  Copyright © 2015年 quan. All rights reserved.
//

#import "HQZhou.h"

@implementation HQZhou

- (instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

+ (instancetype)zhouWithDitc:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}

- (NSString *)ingredients{
    NSMutableString *originString = [NSMutableString stringWithString:_ingredients];
    [originString replaceOccurrencesOfString:@"<br>" withString:@" , " options:NSCaseInsensitiveSearch range:NSMakeRange(0, originString.length) ];
    return originString;
    
}

- (NSString *)steps{
    NSMutableString *originString = [NSMutableString stringWithString:_steps];
    [originString replaceOccurrencesOfString:@"<p>" withString:@" \n " options:NSCaseInsensitiveSearch range:NSMakeRange(0, originString.length) ];
    return originString;
}




+ (NSArray *)zhous{
    NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"CB_Recipe" ofType:@"json"];
    NSString *sourceString = [NSString stringWithContentsOfFile:jsonPath encoding:NSUTF8StringEncoding error:nil];
    NSData *data = [sourceString dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *sourceDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSArray *sourceArr = sourceDict[@"RECORDS"];
    NSMutableArray *descArr = [NSMutableArray array];
    
    for (NSDictionary *dict in sourceArr) {
        
        HQZhou *zhou = [HQZhou zhouWithDitc:dict];
        [descArr addObject:zhou];
        
    }
    return descArr;
}



- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeInt:self.id forKey:@"id"];
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.ingredients forKey:@"ingredients"];
    [aCoder encodeObject:self.steps forKey:@"steps"];
    [aCoder encodeObject:self.category forKey:@"category"];
    [aCoder encodeObject:self.flavor forKey:@"flavor"];
    [aCoder encodeObject:self.cmode forKey:@"cmode"];
    [aCoder encodeObject:self.caishi forKey:@"caishi"];
    [aCoder encodeObject:self.zhouDescription forKey:@"zhouDescription"];
    [aCoder encodeObject:self.photo forKey:@"photo"];
    
}


- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super init]) {
        self.id = [aDecoder decodeIntForKey:@"id"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.ingredients = [aDecoder decodeObjectForKey:@"ingredients"];
        self.steps = [aDecoder decodeObjectForKey:@"steps"];
        self.category = [aDecoder decodeObjectForKey:@"category"];
        self.flavor = [aDecoder decodeObjectForKey:@"flavor"];
        self.cmode = [aDecoder decodeObjectForKey:@"cmode"];
        self.caishi = [aDecoder decodeObjectForKey:@"caishi"];
        self.zhouDescription = [aDecoder decodeObjectForKey:@"zhouDescription"];
        self.photo = [aDecoder decodeObjectForKey:@"photo"];
    }
    
    return self;
    
}



@end
